package com.lingnan.cmsservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lingnan.cmsservice.entity.CrmBanner;
import com.lingnan.cmsservice.mapper.CrmBannerMapper;
import com.lingnan.cmsservice.service.CrmBannerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 首页banner表 服务实现类
 * </p>
 *
 * @author zzd
 * @since 2021-08-30
 */
@Service
public class CrmBannerServiceImpl extends ServiceImpl<CrmBannerMapper, CrmBanner> implements CrmBannerService {

    /**
     * 查询时间最靠前的5条banner信息
     *
     * @return
     */
    @Override
    public List<CrmBanner> findBanner() {
        // 创建查询条件
        QueryWrapper<CrmBanner> wrapper = new QueryWrapper<>();
        // 按照更新时间进行排序
        wrapper.orderByDesc("gmt_modified");
        // 查询最前面的五条记录
        wrapper.last(" LIMIT 5 ");
        // 执行查询
        List<CrmBanner> crmBannerList = baseMapper.selectList(wrapper);

        return crmBannerList;
    }
}
